/*
easyXDM
http://easyxdm.net/
Copyright(c) 2009, �?yvind Sean Kinsey, oyvind@kinsey.no.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
window._JSON = function() {
function f(n) {
return n < 10 ? "0" + n : n
}
function thisDateToJSON(key) {
return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null
}
function thisValueOf(key) {
return this.valueOf()
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {"\b":"\\b", "\t":"\\t", "\n":"\\n", "\f":"\\f", "\r":"\\r", '"':'\\"', "\\":"\\\\"}, rep;
function quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function(a) {
var c = meta[a];
return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
}) + '"' : '"' + string + '"'
}
function str(key, holder) {
var i, k, v, length, mind = gap, partial, value = holder[key];
if(value && typeof value === "object") {
if(value instanceof Date) {
value = thisDateToJSON.call(value)
}else {
if(value instanceof String || value instanceof Number || value instanceof Boolean) {
value = thisValueOf.call(value)
}
}
}
if(typeof rep === "function") {
value = rep.call(holder, key, value)
}
switch(typeof value) {
case "string":
return quote(value);
case "number":
return isFinite(value) ? String(value) : "null";
case "boolean":
;
case "null":
return String(value);
case "object":
if(!value) {
return"null"
}
gap += indent;
partial = [];
if(Object.prototype.toString.apply(value) === "[object Array]") {
length = value.length;
for(i = 0;i < length;i += 1) {
partial[i] = str(i, value) || "null"
}
v = partial.length === 0 ? "[]" : gap ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]" : "[" + partial.join(",") + "]";
gap = mind;
return v
}
if(rep && typeof rep === "object") {
length = rep.length;
for(i = 0;i < length;i += 1) {
if(typeof rep[i] === "string") {
k = rep[i];
v = str(k, value);
if(v) {
partial.push(quote(k) + (gap ? ": " : ":") + v)
}
}
}
}else {
for(k in value) {
if(Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if(v) {
partial.push(quote(k) + (gap ? ": " : ":") + v)
}
}
}
}
v = partial.length === 0 ? "{}" : gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" : "{" + partial.join(",") + "}";
gap = mind;
return v
}
}
return{stringify:function(value, replacer, space) {
var i;
gap = "";
indent = "";
if(typeof space === "number") {
for(i = 0;i < space;i += 1) {
indent += " "
}
}else {
if(typeof space === "string") {
indent = space
}
}
rep = replacer;
if(replacer && typeof replacer !== "function" && (typeof replacer !== "object" || typeof replacer.length !== "number")) {
throw new Error("JSON.stringify");
}
return str("", {"":value})
}, parse:function(text, reviver) {
var j;
function walk(holder, key) {
var k, v, value = holder[key];
if(value && typeof value === "object") {
for(k in value) {
if(Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if(v !== undefined) {
value[k] = v
}else {
delete value[k]
}
}
}
}
return reviver.call(holder, key, value)
}
text = String(text);
cx.lastIndex = 0;
if(cx.test(text)) {
text = text.replace(cx, function(a) {
return"\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
})
}
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
j = eval("(" + text + ")");
return typeof reviver === "function" ? walk({"":j}, "") : j
}
throw new SyntaxError("JSON.parse");
}}
}();
(function(window, document, location, setTimeout, decodeURIComponent, encodeURIComponent) {
if("easyXDM" in window) {
return
}
var global = this;
var channelId = 0;
var emptyFn = Function.prototype;
var reURI = /^(http.?:\/\/([^\/\s]+))/;
var reParent = /[\-\w]+\/\.\.\//;
var reDoubleSlash = /([^:])\/\//g;
var IFRAME_PREFIX = "easyXDM_";
var HAS_NAME_PROPERTY_BUG;
function isHostMethod(object, property) {
var t = typeof object[property];
return t == "function" || !!(t == "object" && object[property]) || t == "unknown"
}
function isHostObject(object, property) {
return!!(typeof object[property] == "object" && object[property])
}
function isArray(o) {
return Object.prototype.toString.call(o) === "[object Array]"
}
var on, un;
if(isHostMethod(window, "addEventListener")) {
on = function(target, type, listener) {
target.addEventListener(type, listener, false)
};
un = function(target, type, listener) {
target.removeEventListener(type, listener, false)
}
}else {
if(isHostMethod(window, "attachEvent")) {
on = function(object, sEvent, fpNotify) {
object.attachEvent("on" + sEvent, fpNotify)
};
un = function(object, sEvent, fpNotify) {
object.detachEvent("on" + sEvent, fpNotify)
}
}else {
throw new Error("Browser not supported");
}
}
var isReady = false, domReadyQueue = [];
if("readyState" in document) {
isReady = document.readyState == "complete" || document.readyState == "interactive"
}else {
if(document.body) {
isReady = true
}
}
function dom_onReady() {
dom_onReady = emptyFn;
isReady = true;
for(var i = 0;i < domReadyQueue.length;i++) {
domReadyQueue[i]()
}
domReadyQueue.length = 0
}
if(!isReady) {
if(isHostMethod(window, "addEventListener")) {
on(document, "DOMContentLoaded", dom_onReady)
}else {
on(document, "readystatechange", function() {
if(document.readyState == "complete") {
dom_onReady()
}
});
if(document.documentElement.doScroll && window === top) {
(function doScrollCheck() {
if(isReady) {
return
}
try {
document.documentElement.doScroll("left")
}catch(e) {
setTimeout(doScrollCheck, 1);
return
}
dom_onReady()
})()
}
}
on(window, "load", dom_onReady)
}
function whenReady(fn, scope) {
if(isReady) {
fn.call(scope);
return
}
domReadyQueue.push(function() {
fn.call(scope)
})
}
function getDomainName(url) {
return url.match(reURI)[2]
}
function getLocation(url) {
return url.match(reURI)[1]
}
function resolveUrl(url) {
url = url.replace(reDoubleSlash, "$1/");
if(!url.match(/^(http||https):\/\//)) {
var path = url.substring(0, 1) === "/" ? "" : location.pathname;
if(path.substring(path.length - 1) !== "/") {
path = path.substring(0, path.lastIndexOf("/") + 1)
}
url = location.protocol + "//" + location.host + path + url
}
while(reParent.test(url)) {
url = url.replace(reParent, "")
}
return url
}
function appendQueryParameters(url, parameters) {
var hash = "", indexOf = url.indexOf("#");
if(indexOf !== -1) {
hash = url.substring(indexOf);
url = url.substring(0, indexOf)
}
var q = [];
for(var key in parameters) {
if(parameters.hasOwnProperty(key)) {
q.push(key + "=" + encodeURIComponent(parameters[key]))
}
}
return url + (url.indexOf("?") === -1 ? "?" : "&") + q.join("&") + hash
}
var query = function() {
var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length;
while(i--) {
pair = search[i].split("=");
try {
query[pair[0]] = decodeURIComponent(pair[1])
}catch(e) {
}
}
return query
}();
function undef(v) {
return typeof v === "undefined"
}
var getJSON_initTS = Math.floor(new Date / 1E3), getJSON_lastTS = getJSON_initTS, getJSON_loadedTS = 0, getJSON_useCounter = 0, getJSON_nativeIsBroken = false, getJSON_testStringify = document.location.hostname.indexOf("my.mail.ru") > -1;
function getJSON() {
if(window.JSON && window.JSON.stringify(["a"]) === '["a"]') {
return{stringify:function() {
if(getJSON_testStringify) {
var now = Math.floor(new Date / 1E3);
getJSON_useCounter++;
getJSON_nativeIsBroken = window.JSON.stringify(["a"]) != '["a"]';
if(getJSON_nativeIsBroken) {
getJSON_testStringify = false
}else {
if(document.readyState == "complete" && !getJSON_loadedTS) {
getJSON_loadedTS = now
}
}
getJSON_lastTS = now
}
return getJSON_nativeIsBroken ? window._JSON.stringify.apply(window._JSON, arguments) : window.JSON.stringify.apply(window.JSON, arguments)
}, parse:function() {
return window.JSON.parse.apply(window.JSON, arguments)
}}
}else {
return window._JSON
}
var cached = {};
var obj = {a:[1, 2, 3]}, json = '{"a":[1,2,3]}';
if(JSON && typeof JSON.stringify === "function" && JSON.stringify(obj).replace(/\s/g, "") === json) {
return JSON
}
if(Object.toJSON) {
if(Object.toJSON(obj).replace(/\s/g, "") === json) {
cached.stringify = Object.toJSON
}
}
if(typeof String.prototype.evalJSON === "function") {
obj = json.evalJSON();
if(obj.a && obj.a.length === 3 && obj.a[2] === 3) {
cached.parse = function(str) {
return str.evalJSON()
}
}
}
if(cached.stringify && cached.parse) {
getJSON = function() {
return cached
};
return cached
}
return null
}
function apply(destination, source, noOverwrite) {
var member;
for(var prop in source) {
if(source.hasOwnProperty(prop)) {
if(prop in destination) {
member = source[prop];
if(typeof member === "object") {
apply(destination[prop], member, noOverwrite)
}else {
if(!noOverwrite) {
destination[prop] = source[prop]
}
}
}else {
destination[prop] = source[prop]
}
}
}
return destination
}
function testForNamePropertyBug() {
var el = document.createElement("iframe");
el.name = "easyXDM_TEST";
apply(el.style, {position:"absolute", left:"-2000px", top:"0px"});
document.body.appendChild(el);
HAS_NAME_PROPERTY_BUG = !(el.contentWindow === window.frames[el.name]);
document.body.removeChild(el)
}
function createFrame(config) {
if(undef(HAS_NAME_PROPERTY_BUG)) {
testForNamePropertyBug()
}
var frame;
if(HAS_NAME_PROPERTY_BUG) {
frame = document.createElement('')
}else {
frame = document.createElement("IFRAME");
frame.name = config.props.name
}
frame.id = frame.name = config.props.name;
delete config.props.name;
if(config.onLoad) {
on(frame, "load", config.onLoad)
}
if(typeof config.container == "string") {
config.container = document.getElementById(config.container)
}
if(!config.container) {
frame.style.position = "absolute";
frame.style.left = "-2000px";
frame.style.top = "0px";
config.container = document.body
}
frame.border = frame.frameBorder = 0;
config.container.insertBefore(frame, config.container.firstChild);
if(config.onLoadSrc) {
on(frame, "load", function() {
if(frame.src) {
config.onLoadSrc && config.onLoadSrc(frame)
}
})
}
apply(frame, config.props);
return frame
}
function checkAcl(acl, domain) {
if(typeof acl == "string") {
acl = [acl]
}
var re, i = acl.length;
while(i--) {
re = acl[i];
re = new RegExp(re.substr(0, 1) == "^" ? re : "^" + re.replace(/(\*)/g, ".$1").replace(/\?/g, ".") + "$");
if(re.test(domain)) {
return true
}
}
return false
}
function prepareTransportStack(config) {
var protocol = config.protocol, stackEls;
config.isHost = config.isHost || undef(query.xdm_p);
if(!config.props) {
config.props = {}
}
if(!config.isHost) {
config.channel = query.xdm_c;
config.secret = query.xdm_s;
config.remote = query.xdm_e;
protocol = query.xdm_p;
if(config.acl && !checkAcl(config.acl, config.remote)) {
throw new Error("Access denied for " + config.remote);
}
}else {
config.remote = resolveUrl(config.remote);
config.channel = config.channel || "default" + channelId++;
config.secret = Math.random().toString(16).substring(2);
if(undef(protocol)) {
if(getLocation(location.href) == getLocation(config.remote)) {
protocol = "4"
}else {
if(isHostMethod(window, "postMessage") || isHostMethod(document, "postMessage")) {
protocol = "1"
}else {
if(isHostMethod(window, "ActiveXObject") && isHostMethod(window, "execScript")) {
protocol = "3"
}else {
if(navigator.product === "Gecko" && "frameElement" in window && navigator.userAgent.indexOf("WebKit") == -1) {
protocol = "5"
}else {
if(config.remoteHelper) {
config.remoteHelper = resolveUrl(config.remoteHelper);
protocol = "2"
}else {
protocol = "0"
}
}
}
}
}
}
}
switch(protocol) {
case "0":
apply(config, {interval:100, delay:2E3, useResize:true, useParent:false, usePolling:false}, true);
if(config.isHost) {
if(!config.local) {
var domain = location.protocol + "//" + location.host, images = document.body.getElementsByTagName("img"), image;
var i = images.length;
while(i--) {
image = images[i];
if(image.src.substring(0, domain.length) === domain) {
config.local = image.src;
break
}
}
if(!config.local) {
config.local = window
}
}
var parameters = {xdm_c:config.channel, xdm_p:0};
if(config.local === window) {
config.usePolling = true;
config.useParent = true;
config.local = location.protocol + "//" + location.host + location.pathname + location.search;
parameters.xdm_e = config.local;
parameters.xdm_pa = 1
}else {
parameters.xdm_e = resolveUrl(config.local)
}
if(config.container) {
config.useResize = false;
parameters.xdm_po = 1
}
config.remote = appendQueryParameters(config.remote, parameters)
}else {
apply(config, {channel:query.xdm_c, remote:query.xdm_e, useParent:!undef(query.xdm_pa), usePolling:!undef(query.xdm_po), useResize:config.useParent ? false : config.useResize})
}
stackEls = [new easyXDM.stack.HashTransport(config), new easyXDM.stack.ReliableBehavior({}), new easyXDM.stack.QueueBehavior({encode:true, maxLength:4E3 - config.remote.length}), new easyXDM.stack.VerifyBehavior({initiate:config.isHost})];
break;
case "1":
stackEls = [new easyXDM.stack.PostMessageTransport(config)];
break;
case "2":
stackEls = [new easyXDM.stack.NameTransport(config), new easyXDM.stack.QueueBehavior, new easyXDM.stack.VerifyBehavior({initiate:config.isHost})];
break;
case "3":
stackEls = [new easyXDM.stack.NixTransport(config)];
break;
case "4":
stackEls = [new easyXDM.stack.SameOriginTransport(config)];
break;
case "5":
stackEls = [new easyXDM.stack.FrameElementTransport(config)];
break
}
stackEls.push(new easyXDM.stack.QueueBehavior({lazy:config.lazy, remove:true}));
return stackEls
}
function chainStack(stackElements) {
var stackEl, defaults = {incoming:function(message, origin) {
this.up.incoming(message, origin)
}, outgoing:function(message, recipient) {
this.down.outgoing(message, recipient)
}, callback:function(success) {
this.up.callback(success)
}, init:function() {
this.down.init()
}, destroy:function() {
this.down.destroy()
}};
for(var i = 0, len = stackElements.length;i < len;i++) {
stackEl = stackElements[i];
apply(stackEl, defaults, true);
if(i !== 0) {
stackEl.down = stackElements[i - 1]
}
if(i !== len - 1) {
stackEl.up = stackElements[i + 1]
}
}
return stackEl
}
function removeFromStack(element) {
element.up.down = element.down;
element.down.up = element.up;
element.up = element.down = null
}
global.easyXDM = {version:"2.4.9.102", query:query, stack:{}, apply:apply, getJSONObject:getJSON, whenReady:whenReady};
easyXDM.DomHelper = {on:on, un:un, requiresJSON:function(path) {
if(!isHostObject(window, "JSON")) {
document.write('